<?php

use yii\helpers\Html;

$this->title = $product->name . '  ' . $product->go_time;
?>

<?= yii\web\View::registerCssFile("/css/magic-check.css",['depends' => 'app\assets\AppAsset']) ?>
<style type="text/css">
	.order-view font {color:#9E9A9A;margin-right:10px;}
	.order{border: 1px solid #ddd;text-align: center;height: 100px;background: #dff0d8;line-height: 100px;border-radius: 4px;}
</style>

<div class="order-view">

    <h2 class="page-header">
    	 <small><?=yii::$app->params['template'][$template_id]?></small>
    	 &nbsp;&nbsp;<small>[ <?= Html::encode($this->title) ?> ]</small>
    </h2>

    <input type="hidden" name="template_id" id="template_id" value="<?=$template_id?>">
	<input type="hidden" name="product_id" id="product_id" value="<?=$product->id?>">
	<input type="hidden" value="<?php echo Yii::$app->getRequest()->getCsrfToken(); ?>" name="_csrf" id="_csrf" />
	<input type="hidden" name="type" id="type" value="<?=$type?>">
	<div class="row">
    	 
    	 <div class="col-md-6">

    	 		<div class="panel panel-default">
					  <div class="panel-heading">
					    <h3 class="panel-title">选择订单条件</h3>
					  </div>
					  <div class="panel-body">
					    	<ul class="list-group">
							 <!--  <li class="list-group-item">
							  	<input class="magic-radio type_order" type="radio" name="radio" id="11" value="1" </?=($type == 1)?"checked":''?> >
 								<label for="11">已审核订单</label>
							  </li> -->
							  <li class="list-group-item">
							  	<input class="magic-radio type_order" type="radio" name="radio" id="22" value="2" <?=($type == 2)?"checked":''?> >
 								<label for="22">已付款订单</label>
 							  </li>
 							  <li class="list-group-item">
							  	<input class="magic-radio type_order" type="radio" name="radio" id="44" value="4" <?=($type == 4)?"checked":''?> >
 								<label for="44">已提交订单</label>
 							  </li>
							  <li class="list-group-item">
							  	<input class="magic-radio type_order" type="radio" name="radio" id="33" value="3" <?=($type == 3)?"checked":''?> >
 							 	<label for="33">全部</label>
 							  </li>
							</ul>
					  </div>
				</div>
    	 </div>		

    	 <div class="col-md-6">
    	 	<div class="row">
    	 		<div class="col-md-6">
	    	 		<div class="order">
	    	 			 总计<span id="order_num"><?=$order_num?></span>个订单
	    	 		</div>
    	 		</div>
    	 		<div class="col-md-6">
	    	 		<div class="order">
	    	 			 总计<span id="people_num"><?=$people_num?></span>人
	    	 		</div>
    	 		</div>
    	 	</div>
    	 </div>	
	</div>

	<div class="row"  style="text-align: center;margin-top: 30px;">
		
		<button type="button" class="btn btn-warning" id="create_name">生成团队名单</button>
	
	</div>
	
</div>


<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">

$('input:radio[name="radio"]').change(function(){

	var type = $("input[name='radio']:checked").val();
	var product_id = $("#product_id").val();
	$("#type").val(type);
	$.get("/order/customer/get-num", {type:type,product_id:product_id}, function(data){
        var data = $.parseJSON(data);	
        if(data){
            $("#order_num").text(data.order_num);
            $("#people_num").text(data.people_num);
        }
    });
});


$("#create_name").click(function(){

	var template_id = $("#template_id").val();
	var product_id = $("#product_id").val();
	var _csrf = $("#_csrf").val();
	var type = $("#type").val();

	$.ajax({
		   type: "POST",
		   async:false, 
		   url: "/order/customer/excel",
		   data: {"_csrf":_csrf,"template_id":template_id,"product_id":product_id,"type":type},
		   success: function(msg){
		       var res = $.parseJSON(msg);
		       if(res.status == 0){
		       	   alert("生成团队名单失败");
		       	   return false;
		       }else if(res.status == 1){
		       		var href = encodeURI("/order/customer/download-file?name="+res.data.down_name+"&url="+res.data.down_url);
					console.log(href);
		       		window.location.href = href;
		       }

		   }
		});

});

</script>
<?php app\components\JsBlock::end() ?>
